﻿using System;
//using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace AMS.DeDuplicator.CommonLayer
{
    public static class RecycleBin
    {
        private const int CSIDL_BITBUCKET = (int)0x000a;

        [DllImport("coredll.dll")]
        static extern int SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, int nFolder, int fCreate);

        [DllImport("Shell32.dll")]
        static extern int SHGetSpecialFolderPath(IntPtr hwndOwner, IntPtr lpszPath, int nFolder, int fCreate);

        public static string GetPath_Core() // Uses CoreDLL.dll
        {
            StringBuilder resultPath = new StringBuilder(255);
            IntPtr handle = Process.GetCurrentProcess().Handle;
            SHGetSpecialFolderPath(handle, resultPath, CSIDL_BITBUCKET, 0);
            return resultPath.ToString();
        }

        public static string GetPath() // uses Shell32.dll
        {
            IntPtr path = Marshal.AllocHGlobal(260);
            IntPtr handle = Process.GetCurrentProcess().Handle;
            SHGetSpecialFolderPath(handle, path, CSIDL_BITBUCKET, 0);
            //return Marshal.PtrToStringUni(path);
            return Marshal.PtrToStringAnsi(path);
        }
    }
}
